package com.wangshili.sys.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wangshili.common.annotation.RequiredLog;
import com.wangshili.pojo.common.vo.JsonResult;
import com.wangshili.pojo.sys.entity.SysDept;
import com.wangshili.sys.service.SysDeptService;

@RestController
@RequestMapping("/dept/")
public class SysDeptController {
	
	@Autowired
	private SysDeptService sysDeptService;
	
	/**
	 * 查询Dept所有的部门id，name,父id封装到SysZTreeNode类里
	 * @return SysZTreeNode类的list集合
	 */
	@RequestMapping("doFindZTreeNodes")
	public JsonResult doFindZTreeNodes() {
		return new JsonResult(sysDeptService.listDeptZTreeNodes());
	}
	
	
	/**
	 * 查找全部的部门信息和上级部门名称
	 * @return SysDeptParent
	 */
	@RequiredLog("查询操作")
	@RequestMapping("doFindObjects")
	public JsonResult doFindObjects() {
		return new JsonResult(sysDeptService.selectSysDeptParent());
	}
	
	/**
	 * 根据id删除部门信息
	 * @return 
	 */
	@RequiredLog("删除操作")
	@RequestMapping("doDeleteObjectById")
	public JsonResult doDeleteObject(Integer id) {
		sysDeptService.deleteObjectById(id);
		return new JsonResult("删除成功");
	}
	
	/**
	 * 添加部门信息
	 * @return 
	 */
	@RequiredLog("保存操作")
	@RequestMapping("doSaveObject")
	public JsonResult doSaveObject(SysDept entity) {
		sysDeptService.insertObject(entity);
		return new JsonResult("添加成功");
	}
	
	/**
	 * 修改部门信息
	 * @return 
	 */
	@RequiredLog("更新操作")
	@RequestMapping("doUpdateObject")
	public JsonResult doUpdateObject(SysDept entity) {
		sysDeptService.updateObject(entity);
		return new JsonResult("修改成功");
	}

}
